﻿@{
    ViewBag.Title = "OutStockIndex";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Head
{
    @Html.Css("EditForm", "RightSeparateModule", "dp")
    @Html.Js("datepicker")
    @*<script type="text/javascript" src="../../Scripts/datepicker-zh.js"></script>*@
    <script type="text/javascript">

        $(function () {
            var mainheight = document.documentElement.clientHeight;
            var mainWidth = document.documentElement.clientWidth - 10;
            $("#StorageBegin").datepicker({ picker: "<img class='picker' align='middle' src='../../Images/icons/s.gif' alt=''/>" });
            $("#StorageEnd").datepicker({ picker: "<img class='picker' align='middle' src='../../Images/icons/s.gif' alt=''/>" });
            var gh = mainheight - 180;
            $("#ArticleList").bind("change", function () {
              
                    $.post('@Url.Action("RtnStorageInfoForUnit", "Storage")', { "Id": $("#ArticleList").val(), "random": Math.random() }, function (data) {
                        $("#StorageNo").val(data.ArticleNO);
                        TtnUnitList(data.ArticleUnit, data.ArticleUnitId);
                    });



            });

            function TtnUnitList(ArticleUnit, ArticleUnitId) {

                if (ArticleUnit != null && ArticleUnit != "") {
                    var charUnit = ArticleUnit.split(',');
                    var charUnitId = ArticleUnitId.split(',');
                    if (charUnit.length > 0) {
                        $("#StorageUnit").children("option").remove();
                        $("<option value='0' selected=selected>请选择... </option>").appendTo($("#StorageUnit"));
                        for (var i = 0; i < charUnitId.length; i++) {
                            $("<option value=" + charUnitId[i] + ">" + charUnit[i] + " </option>").appendTo($("#StorageUnit"));
                        }
                    } //if
                } //if
            } //end
            var option = {
                height: gh,
                width: mainWidth,
                url: '@Url.Action("GetDetailList")',
                colModel: [
                     { display: '编号', name: 'ID', width: 60, sortable: false, align: 'left', hide: true, iskey: true },
                    { display: '调出日期', name: 'OutDt', width: 120, sortable: false, hide: false, align: 'left' },
			        { display: '劳保物品名称', name: 'Article_Name', width: 160, sortable: false, hide: false, align: 'left' },
                    { display: '物品编号', name: 'Article_NO', width: 80, sortable: false, hide: false, align: 'left' },
                    { display: '物品规格', name: 'Article_Unit', width: 80, sortable: false, hide: false, align: 'left' },
                    { display: '调出数量', name: 'Count', width: 80, sortable: false, hide: false, align: 'left' },
                    { display: '操作人', name: 'Operate', width: 120, sortable: false, hide: false, align: 'left' },
                     { display: '备注', name: 'Remark', width: 120, sortable: false, hide: false, align: 'left' },
                    { display: '记录日期', name: 'RecordDateTime', width: 120, sortable: false, hide: true, align: 'left' }
                 ],
                buttons: [
                            { name: 'Add', displayname: "新建", title: "新建", bclass: 'add', onpress: toolbarItem_onclick },
                            { name: 'Edit', displayname: "修改", title: "编辑", bclass: 'edit', onpress: toolbarItem_onclick },
                            { name: 'Delete', displayname: "删除", title: "删除", bclass: 'delete', onpress: toolbarItem_onclick },
                            { separator: true }
                         ],
                singleselected: false,
                sortname: "Sequence",
                sortorder: "asc",
                title: false,
                usepager: true,
                page: 1,
                rp: 20,
                rpOptions: [10, 15, 20],
                showcheckbox: true,
                selectedonclick: true, //点击行是否选中
                rowbinddata: true
            };
            var instockgrid = $("#storageList").flexigrid(option);
            $("#btnQueryList").bind("click", function () {
                refreshbyclick();
            });
            //新增，删除，修改
            function toolbarItem_onclick(cmd, grid) {
                if (cmd == "Add") {
                    OpenModelWindow('@Url.Action("OutAddStorage")', { width: 806, height: 497, caption: "新增劳保物品调出",
                        onclose: refresh
                    });
                }
                else if (cmd == 'Edit') {
                    var ids = "";
                    if ($('.trSelected', grid).length == 0 || $('.trSelected', grid).length > 1) {
                        showLoadingMsg("请选择一行数据进行编辑", { left: 300, top: 2 }, true, 3000);
                        return false;
                    }
                    else {
                        var items = $('.trSelected', grid);
                        for (i = 0; i < items.length; i++) {
                            if (i == items.length - 1) {
                                ids += items[i].id.substr(3);
                            } else {
                                ids += items[i].id.substr(3) + ", ";
                            } //if 
                        } //for
                    }
                    OpenModelWindow('@Url.Action("OutAddStorage")?id=' + ids,
                        {
                            width: 806,
                            height: 497,
                            caption: "维护保物品调出",
                            onclose: refresh
                        });
                }

                else if (cmd == 'Delete') {
                    if ($('.trSelected', grid).length == 0) {
                        showLoadingMsg("请选择要删除的行", { left: 300, top: 2 }, true, 3000);
                        return false;
                    } else {
                        if (confirm("确定要删除吗?")) {
                            var rowcount = 0;
                            var items = $('.trSelected', grid);
                            for (var i = 0; i < items.length; i++) {
                                var id = items[i].id.substr(3);
                                $.ajax({
                                    url: '@Url.Action("Delete")',
                                    type: "POST",
                                    data: { id: id },
                                    async: false,
                                    success: function (data) {
                                        if (data) {
                                            rowcount = rowcount + data;
                                        }
                                    },
                                    error: function () {
                                    }
                                });
                            } //for
                            if ($("#orderno").val()) {
                                refresh();
                            }
                            else {
                                refreshbyclick();
                            }
                            showLoadingMsg("共有" + rowcount.toString() + "个物品调出记录删除!", { left: 400, top: 6 }, true, 3000);
                        }
                    }
                }
            } // end of toolbarItem_onclick
            function refreshbyclick() {
                var idt = ($("#StorageBegin").val() == null) ? "" : $("#StorageBegin").val();
                var iname = ($("#ArticleList").val() == "0") ? "" : $("#ArticleList").val();
                var enddt = ($("#StorageEnd").val() == null) ? "" : $("#StorageEnd").val();
                var gu = ($("#StorageUnit").val() == "0") ? "" : $("#StorageUnit").val();

                var oper = ($("#Operate").val() == null) ? "" : $("#Operate").val();
               
                option.query = "and ((OutDt >= '" + idt + "') and (OutDt <='" + enddt + "')) and "
                            + "((Article_ID = '" + iname + "') or ('" + iname + "'='')) and "
                            + "((Operate like '%" + oper + "%') or ('" + oper + "'='')) and "
                            + "((Article_Unit= '" + gu + "') or ('" + gu + "'=''))";
                option.newp = 0;
                $('#storageList').flexOptions(option).flexReload();
            }
            function refresh() {
                option.query = "and OrderNo = '" + $("#orderno").val() + "'";
                option.newp = 0;
                $("#storageList").flexOptions(option).flexReload();
            }

        });
    </script>
}
<div id="container">
    <div id="mainContent">
        <div id="title" class="title">
            劳保调出物品列表</div>
        <div id="findDiv">
            @Html.Hidden("orderno")
            <table>
                <tr>
                    <td style="text-align: right; width: 80px;">
                        开始日期:
                    </td>
                    <td>
                        @Html.TextBox("StorageBegin", DateTime.Now.Date.ToString("yyyy-MM-dd"), new { @ReadOnly = true })
                    </td>
                    <td style="text-align: right; width: 80px;">
                        结束日期:
                    </td>
                    <td>
                        @Html.TextBox("StorageEnd", DateTime.Now.Date.ToString("yyyy-MM-dd"), new { @ReadOnly = true })
                    </td>
                    <td style="text-align: right; width: 160px;">
                        劳防物品名称：
                    </td>
                    <td>
                        @Html.DropDownList("ArticleList", ViewBag.ArticleList as IEnumerable<SelectListItem>)
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right; width: 80px;">
                        规格/型号:
                    </td>
                    <td>
                        @Html.DropDownList("StorageUnit", ViewBag.UnitList as IEnumerable<SelectListItem>, new { @style = "width:140px;height:20px;" })
                    </td>
                    <td style="text-align: right; width: 80px;">
                        操作人:
                    </td>
                    <td>
                        @Html.TextBox("Operate")
                    </td>
                    <td>
                        <a id="btnQueryList" class="button" href="javascript:void(0);"><span>查 询</span></a>
                    </td>
                </tr>
            </table>
        </div>
        <table id="storageList" style="display: none;">
        </table>
    </div>
</div>
